var t = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (t) {
  return typeof t
}
  : function (t) {
    return t && "function" == typeof Symbol && t.constructor === Symbol && t !== Symbol.prototype ? "symbol" : typeof t
  },
  e = getApp(), 
  a = e.requirejs("core"),
  r = e.requirejs("check");
Page({
  data: {
    icons: e.requirejs("icons"),
    list: {},
    data: [],
    showPicker: false,
    pvalOld: [0, 0, 0],
    pval: [0, 0, 0],
    areas: [],
    noArea: true,
    submit: true,
    button_color: e.config.button_color
  },
  onLoad: function (t) {
    a.setting();
    var i = this,
      data=this.data,
      d = {};
    this.setData({
      options: t,
      button_color: getApp().config.button_color
    })
     
    //获取用户地址
    a.get("Area/UserAddress", { uid: getApp().getCache("userinfo").uid  }, function (t) {
      if(t.code==0){
        i.setData({
          address: t.info.address,
        })
        //获取订单信息
        a.get("Bargain/GoodsInfo", { id: i.data.options.bargain_id }, function (t) {
          0 == t.code ? (
            i.setData({
              list: t.info.bargain_info,
              show: true,
            }),
            i.caculate()
          ) : a.alert(t.msg)
        }, true)
      }else{
        a.alert(t.msg)
      }
        
    })
     
  },
  onShow: function () {
    var i = this,
      d = e.getCache("orderAddress");
    if (d) {
      this.setData({
        address: d,
      })
        i.caculate()
    }
    
  },
  /**
   *返回触发事件
   * @param t 事件
   * @return array
   */
  toggle: function (t) {
    var e = a.pdata(t),
      i = e.id,
      d = e.type,
      r = {};
    r[d] = 0 == i || void 0 === i ? 1 : 0,
      this.setData(r)
  },
  /**
   *打电话
   */
  phone: function (t) {
    a.phone(t)
  },

  //计算
  caculate: function () {
    var e = this,
      a = e.data.address;
      //订单价
    a.order_money = e.data.options.current_price;
    //运费
    // a.shipping_money = e.data.options.total * e.data.list.goods.shipping_fee;
    //实付价
    //a.pay_money = parseFloat(e.data.options.total * (e.data.list.price - e.data.list.goods.shipping_fee) - discount_money);
      a.pay_money = e.data.options.current_price;
      a.total = e.data.options.total;
      a.user_name = getApp().getCache("userinfo").nickName;
      a.buyer_id = getApp().getCache("userinfo").uid;
      a.mch_id = e.data.list.mch_id;
      a.activity_order_type = e.data.options.activity_order_type ? e.data.options.activity_order_type:0;
      a.bargain_id = e.data.options.bargain_id;
      e.setData({
        data: a
      })
  },
  //提交订单
  submit: function () {
    var e = this,
      t = this.data;
    if (!t.submit) {
      wx.navigateTo({
        url: "/yb_shop/pages/kanjia/order/pay/index?id=" + e.data.order_id
      })
    } else {
      if (!t.address.phone || t.address.province == '') {
        a.alert('请选择收货地址！');
        return false;
      }
      
      a.get("Bargain/CreateOrder", t.data, function (t) {
        if(0 == t.code ){
          e.setData({
            submit: false,
            order_id: t.info
          }),
          wx.navigateTo({
            url: "/yb_shop/pages/kanjia/order/pay/index?id=" + t.info
          })
        }else{
          a.alert(t.msg)
        }
      })
    }

  },
  dataChange: function (t) {
    var e = this.data.data,
      a = this.data.list;
    switch (t.target.id) {
      case "buyer_message":  //留言
        e.buyer_message = t.detail.value;
        break;
    }
    this.setData({
      data: e,
      //list: a
    })
  },
  radioChange:function(e){
    //console.log(e.detail.value)
    this.setData({
      data: e,
      //list: a
    })
  },

  url: function (t) {
    var e = a.pdata(t).url;
    wx.redirectTo({
      url: e
    })
  },
  /**
* 下拉刷新
*/
  onPullDownRefresh: function () {
    wx.stopPullDownRefresh();
  },
  
})